﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace MineSweeping.AppCode
{
    public class ShowTimeConverter :　IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int showtime = int.Parse(value.ToString());
            return showtime.ToString("D3");
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class BtnFlagVisbilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool isGameRunning = (bool) value;
            return isGameRunning ? Visibility.Visible : Visibility.Collapsed;
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class BtnFlagBackgroundConverter : IValueConverter
    {
        private static readonly ImageBrush flagOn = new ImageBrush
        {
            ImageSource = new BitmapImage(new Uri("/Picture/GameFlagOn.png", UriKind.Relative))
        };

        private static readonly ImageBrush flagOff = new ImageBrush
        {
            ImageSource = new BitmapImage(new Uri("/Picture/GameFlagOff.png", UriKind.Relative))
        };

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool isFlaging = (bool)value;
            return isFlaging ? flagOn : flagOff;
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public class ImageStatusSourceConverter : IValueConverter
    {
        private static readonly BitmapImage smileFaceSource = new BitmapImage(new Uri("/Picture/SmileFace.png", UriKind.Relative));

        private static readonly BitmapImage sadFaceSource = new BitmapImage(new Uri("/Picture/SadFace.png", UriKind.Relative));


        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool isLosing = (bool)value;
            return isLosing ? sadFaceSource : smileFaceSource;
        }

        // Not need here
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
